<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="description" content="Partytown Test Page" />
    <title>Integration Config</title>

    <style>
      body {
        font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif,
          Apple Color Emoji, Segoe UI Emoji;
        font-size: 12px;
      }
      h1 {
        margin: 0 0 15px 0;
      }
      ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
      }
      a {
        display: block;
        padding: 16px 8px;
      }
      a:link,
      a:visited {
        text-decoration: none;
        color: blue;
      }
      a:hover {
        background-color: #eee;
      }
      li {
        display: flex;
        margin: 15px 0;
      }
      li strong,
      li code,
      li button {
        white-space: nowrap;
        flex: 1;
        margin: 0 5px;
      }
    </style>
  </head>
  <body>
    <h1>Integration Config</h1>

    <script>
      partytown = {
        get(opts) {
          if (opts.name === 'dir') {
            return 'hooked-getter';
          }
          if (opts.constructor === 'Window' && opts.name === 'innerWidth') {
            return 999;
          }
          return opts.continue;
        },
        set: (opts) => {
          if (opts.name === 'innerHTML' && opts.nodeName === 'BODY') {
            return opts.prevent;
          }
          if (opts.name === 'innerText' && opts.constructor === 'HTMLSpanElement') {
            return 'hooked-' + opts.nodeName + '-' + opts.name + '-' + opts.value;
          }
          return opts.continue;
        },
        apply: function (opts) {
          if (opts.nodeName === '#document' && opts.name === 'write') {
            return undefined;
          }
          if (opts.args[0] === 'gw') {
            opts.args[1] = '1.21';
          }
          return opts.continue;
        },
        logCalls: true,
        logGetters: true,
        logSetters: true,
        logStackTraces: false,
        logScriptExecution: true,
      };
    </script>
    <script src="/~partytown/debug/partytown.js"></script>

    <ul>
      <li>
        <strong>get() continue</strong>
        <code id="testGetContinue"></code>
        <script type="text/partytown">
          (function () {
            document.getElementById('testGetContinue').textContent = document.title;
          })();
        </script>
      </li>

      <li>
        <strong>get() hook</strong>
        <code id="testGetHook"></code>
        <script type="text/partytown">
          (function () {
            document.getElementById('testGetHook').textContent = document.dir;
          })();
        </script>
      </li>

      <li>
        <strong>get() window.innerWidth</strong>
        <code id="testGetWindowHook"></code>
        <script type="text/partytown">
          (function () {
            document.getElementById('testGetWindowHook').textContent = window.innerWidth;
          })();
        </script>
      </li>

      <li>
        <strong>set() continue</strong>
        <code id="testSetContinue"></code>
        <script type="text/partytown">
          (function () {
            document.title = 'Continue Title Update';
            document.getElementById('testSetContinue').textContent = document.title;
          })();
        </script>
      </li>

      <li>
        <strong>set() prevent</strong>
        <code id="testSetPrevent"></code>
        <script type="text/partytown">
          (function () {
            document.body.innerHTML = 'smash!';
            document.getElementById('testSetPrevent').textContent = 'prevented body.innerHTML';
          })();
        </script>
      </li>

      <li>
        <strong>set() hook</strong>
        <code><span id="testSetHook"></span></code>
        <script type="text/partytown">
          (function () {
            document.getElementById('testSetHook').innerText = 'value';
          })();
        </script>
      </li>

      <li>
        <strong>apply() continue</strong>
        <code id="testApplyContinue"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testApplyContinue');
            elm.setAttribute('mph', 88);
            document.getElementById('testApplyContinue').textContent = elm.getAttribute('mph');
          })();
        </script>
      </li>

      <li>
        <strong>apply() hook</strong>
        <code id="testApplyHook"></code>
        <script type="text/partytown">
          (function () {
            document.write('smash!');
            document.getElementById('testApplyHook').textContent = 'prevented document.write()';
          })();
        </script>
      </li>

      <li>
        <strong>apply() change args</strong>
        <code id="testApplyArgs"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testApplyArgs');
            elm.setAttribute('gw', '9.99');
            elm.textContent = elm.getAttribute('gw');
          })();
        </script>
      </li>
    </ul>

    <script type="text/partytown">
      document.body.classList.add('completed');
    </script>

    <hr />
    <p><a href="/tests/">All Tests</a></p>
  </body>
</html>
